/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package config;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.GregorianCalendar;
import views.utilitario.ResultadoTestes;

/**
 *
 * @author Wenderson
 */
public class LogErro {
 
    public static boolean gravaErro(Throwable erro) {
        GregorianCalendar gc = new GregorianCalendar();
        File file = new File("Log_Erro.txt");
        
        try {
            PrintWriter pw = new PrintWriter(new FileWriter(file, true));
            
            pw.println("Data do Erro: " + gc.getTime().toLocaleString());
            pw.println("Messagem de Erro: " + erro);
            pw.println("Stack Trace: ");
            
            int cont = 0;
            for (StackTraceElement stack : erro.getStackTrace()) {
                if (cont < 3) {
                    pw.println(stack.toString());
                    cont++;
                }
            }
            
            pw.println(" ");
            pw.println("*************************************************");
            pw.println(" ");
            
            pw.close();
            
            return true;
        } catch (Exception e) {
            LogErro.gravaErro(e);LogErro.gravaErro(e);e.printStackTrace();
        } 
        return false;
    }    
    
}
